/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightAdjustInstruction;
import com.sasis.dao.FlightAdjustInstructionDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightAdjustInstructionDaoiBatis extends BaseDaoiBATIS implements FlightAdjustInstructionDao {

    /**
     * @see com.sasis.dao.FlightAdjustInstructionDao#getFlightAdjustInstructions(com.sasis.model.FlightAdjustInstruction)
     */
    public List getFlightAdjustInstructions(final FlightAdjustInstruction flightAdjustInstruction) {
          return getSqlMapClientTemplate().queryForList("getFlightAdjustInstructions", flightAdjustInstruction);
    }

    /**
     * @see com.sasis.dao.FlightAdjustInstructionDao#getFlightAdjustInstruction(Integer id)
     */
    public FlightAdjustInstruction getFlightAdjustInstruction(Integer id) {
        FlightAdjustInstruction flightAdjustInstruction = (FlightAdjustInstruction) getSqlMapClientTemplate().queryForObject("getFlightAdjustInstruction", id);

        //if (flightAdjustInstruction == null) {
            //throw new ObjectRetrievalFailureException(FlightAdjustInstruction.class, id);
        //}

        return flightAdjustInstruction;
    }

    /**
     * @see com.sasis.dao.FlightAdjustInstructionDao#saveFlightAdjustInstruction(FlightAdjustInstruction flightAdjustInstruction)
     */    
    public int saveFlightAdjustInstruction(final FlightAdjustInstruction flightAdjustInstruction) {
        Integer id = flightAdjustInstruction.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightAdjustInstruction", flightAdjustInstruction);
        } else {
            getSqlMapClientTemplate().update("updateFlightAdjustInstruction", flightAdjustInstruction);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightAdjustInstruction.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightAdjustInstructionDao#removeFlightAdjustInstruction(Integer id)
     */
    public void removeFlightAdjustInstruction(FlightAdjustInstruction flightAdjustInstruction) {
        getSqlMapClientTemplate().update("deleteFlightAdjustInstruction",  flightAdjustInstruction);
    }
}
